﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/ListPage.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Sys.WebRes.Data.Section>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	栏目管理画面
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript" language="javascript">
$(function () {
	$('#mainGrid').treegrid({
	    title: '栏目一览',
	    iconCls: 'icon-edit',
	    singleSelect: false,
	    toolbar: [
                { text: '删除选中',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var ids = [];
                        $(".idchk:checked").each(function () { ids.push(this.value); });
                        if (ids.length > 0) {
                            $.messager.confirm('删除确认', '只会删除无子栏目的项，确定继续吗？', function (r) {
                                if (r) {
                                    $.messager.progress({ text: "提交中...", interval: 1000 });
                                    $.post('<%=Url.Action("Delete") %>', $.param({ ids: ids }).replace(/%5B%5D/gi, ""), function (resp) {
                                        $.messager.progress("close");
                                    });
                                }
                            });
                        }
                    }
                }, '-', {
                    text: '新建',
                    iconCls: 'icon-add',
                    handler: function () {
                        $('#editPanel').dialog("open");
                        $('#innerEditPanel').panel("refresh", '<%=Url.Action("Edit")%>');
                    }
                }, '-', {
                    text: '批量编辑',
                    iconCls: 'icon-save',
                    handler: function () {

                    }
                }, '-', {
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        saveNode();
                    }
                }, '-', {
                    text: '自动排序',
                    iconCls: 'icon-sum',
                    handler: function () {

                    }
                }],
	    width: 1000,
	    height: 350,
	    nowrap: true,
	    rownumbers: false,
	    animate: false,
	    striped: true,
	    collapsible: false,
	    remoteSort: false,
	    url: '<%=Url.Action("List")%>',
	    idField: 'ID',
	    treeField: 'Name',
	    columns: [[
	    //{ field: 'ck', checkbox:true},
                {field: 'ID', title: '操作', align: 'center', width: 80, formatter: operatorFormatter },
				{ field: 'Name', title: '名称', width: 150, editor: 'text' },
				{ field: 'LevelNo', title: '级别', width: 30 },
				{ field: 'Abbr', title: '缩写', width: 60, editor: 'text' },
				{ field: 'ResTypeID', title: '资源类型', width: 80, editor: { type: 'combobox', options: { valueField: 'id', textField: 'name', data: resType, required: true} }, formatter: getComboboxFormatter(resType) },
				{ field: 'Summary', title: '概要', width: 300, editor: 'textarea' },
				{ field: 'StatusTypeID', title: '状态', width: 100, editor: { type: 'combobox', options: { valueField: 'id', textField: 'name', data: statusType, required: true} }, formatter: getComboboxFormatter(statusType) },
				{ field: 'Visible1', title: '可见', width: 50, align: 'center', editor: { type: 'checkbox', options: { on: '1', off: ''} }, formatter: checkboxFormatter },
				{ field: 'OrderNo', title: '排序', width: 80, editor: 'numberbox' }
			]],
	    onBeforeEdit: function (row, param) { }
	}); //grid完毕
}); //初始化函数完毕

//
//操作列格式化函数
//
function operatorFormatter(value) {
    return '<input class="idchk" type="checkbox" value="' + value + '"/>' +
	        '<input onclick="editRow(this,' + value + ');" type="button" class="icon-edit" style="width:20px;" val="编辑"/>' +
            '<input onclick="deleteRow(' + value + ');" type="button" class="icon-cut" style="width:20px;" val="删除"/>' +
            ((value < 0)?'*':'　');
}

function checkboxFormatter(value) {
	return '<a href="" onclick="">' + (value == '1' ? '是' : '否') + '</a>';
	return '<input type="checkbox" name="c1" disabled ' + (value == '1' ? 'checked' : '') + ' />';
	return value=='1' ? "√" : "";
}

//	    function getComboboxFormatter(array) {
//            return function(value){
//                for (var i = 0; i < array.length; i++) {
//                    if (array[i].id == value) {
//                        return array[i].name;
//                    }
//	            }
//	            return value;
//            }
//	    }
var editingID = null;
function editRow(btn, id) {
	if (id > 0) {//编辑
	    openWindow("编辑栏目", '<%=Url.Action("Edit") %>/' + id, null, null, 380, 460);
	} else {//新建
	    openWindow("添加栏目", '<%=Url.Action("Edit") %>', null, null, 380, 460);
	}
}
function deleteRow(id) {alert(id)
	$('#mainGrid').treegrid('remove', id);
	$.post('<%=Url.Action("Edit")%>', { id: id, deletedFlag: true }, function (response) {
	    alert(response.result ? "删除成功" : "删除失败");
	});
}

function saveNode() {
	if (editingID != null) {
	    $('#mainGrid').treegrid('endEdit', editingID);
	    var row = $('#mainGrid').treegrid('find', editingID);
	    row.Visible = (row.Visible1 == '1');

	    $.post('<%=Url.Action("Edit")%>', row, function (response) {
	        alert(response.result ? "更新成功" : "更新失败");
	    });
	    editingID = null;
	}
}
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<%--    <h2>栏目管理</h2>--%>
    <div class="demo-info">
		<div class="demo-tip icon-tip"></div>
		<div>
            <%--<a class="easyui-linkbutton" href="javascript:void(0)" onclick="">自动排序</a>--%>
            <ul>
                <li>此画面管理网站所有的栏目。您也可以从左边菜单栏管理已删除的栏目。</li>
            </ul>
        </div>
	</div>
    <div class="operator"></div>
    <table id="mainGrid"></table>
    <div class="demo-info">
		<div class="demo-tip icon-tip"></div>
		<div>
            <%--<a class="easyui-linkbutton" href="javascript:void(0)" onclick="">自动排序</a>--%>
            <ul style="margin-left:30px; padding-left:5px;">
                <li>选中一行您可以添加此行的子栏目。</li>
                <li>删除多个时只会删除没有子栏目的项。如果您要删除父栏目请先清空子栏目。</li>
                <li>自动排序可以把排序号按照现状重新计数。</li>
            </ul>
        </div>
	</div>
</asp:Content>

